<template>
	<view class="content">
		<view class="release_boxO">
			<view class="release_boxO_li">
				<text class="title">选择手机型号</text>
				<view class="release_boxO_li_R" @tap="phoneTap">
					<text class="">{{phoneType}}</text>
					<text class="iconfont icon-you"></text>
				</view>
			</view>
			<view class="release_boxO_li">
				<text class="title">选择维修类型</text>
				<view class="release_boxO_li_R">
					<picker class="picker-item" mode="selector" :range="textList" @change="textChange">
						<view>{{textValue? textList[textValue] :'请选择'}}</view>
					</picker>
					<text class="iconfont icon-you"></text>
				</view>
			</view>
			<view class="release_boxO_li">
				<text class="title">选择服务</text>
				<view class="release_boxO_li_R">
					<picker class="picker-item" mode="selector" :range="service" @change="serviceChange">
						<view>{{serviceValue? service[serviceValue] :'请选择'}}</view>
					</picker>
					<text class="iconfont icon-you"></text>
				</view>
			</view>
		</view>
		<view class="release_boxT">
			<view class="release_boxT_top">
				<view class="release_boxT_title">请您核对维修关键词</view>
				<view class="release_boxT_keyword">
					<text v-for="(item,index) in keyword" :key='index'>{{item.value}}</text>
				</view>
			</view>
			<view class="release_boxT_bottom">
				<view class="release_boxT_title">请填写/核对电话地址</view>
				<view class="release_boxT_contact">
					<view class="release_boxT_contact_li" @tap="contact">
						<text class="name">联系人</text>
						<text class="contact_zi">{{contactN}}</text>
						<text class="iconfont icon-54"></text>
					</view>
					<view class="release_boxT_contact_li"  @tap="contact">
						<text class="name">联系电话</text>
						<text class="contact_zi">{{contactP}}</text>
						<text class="iconfont icon-54"></text>
					</view>
					<view class="release_boxT_contact_li"  @tap="contact">
						<text class="name">地址</text>
						<text class="contact_zi">{{contactA}}{{contactAll}}</text>
						<text class="iconfont icon-54"></text>
					</view>
				</view>
			</view>
		</view>
		<button class="push">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				textList: [
					'碎屏',
					'后壳',
					'耳机'
				],
				service: [
					'上门服务',
					'三天后'
				],
				keyword: [

				],
				textValue: null,
				serviceValue: null,
				phoneType: '请选择',
				contactN:'',
				contactP:'',
				contactA:'',
				contactAll:''
			};
		},
		methods: {
			//选择手机型号
			phoneTap() {
				uni.navigateTo({
					url: '../phoneModel/phoneModel'
				})
			},
			select_phone_succ() {
				let value = uni.getStorageSync('Phone');
				if (value) {
					console.log(value);
					this.phoneType = value.name;
					this.addKeyword({
						value: value.name,
						type: "phonetype"
					})
				}

			},
			textChange(evt) {
				// console.log('picker发送选择改变，携带值为', evt)
				this.textValue = evt.detail.value;
				let value = this.textList[this.textValue];
				console.log(value)
				this.addKeyword({
					value: value,
					type: "type"
				})
			},
			serviceChange(evt) {
				// console.log('picker发送选择改变，携带值为', evt)
				this.serviceValue = evt.detail.value;
				let value = this.service[this.serviceValue];
				this.addKeyword({
					value: value,
					type: "server"
				})
			},
			//添加关键词
			addKeyword(value) {
				let keyword = this.keyword;
				//if关键词length==0
				if (keyword.length == 0) {
					this.keyword.push(value);
				} else {
					let has = false;
					for (let i = 0; i < keyword.length; i++) {
						//if现有类型存在则替换关键词
						if (keyword[i].type == value.type) {
							keyword[i].value = value.value;
							has = true;
						}
					}
					if (!has) {
						this.keyword.push(value);
					}
				}
			},
			//添加地址
			contact() {
				uni.navigateTo({
					url: '../../myads/myads?select=true'
				})
			}
		},
		onShow(item) {
			this.select_phone_succ()
			//拿到地址
			let value = uni.getStorageSync('ads');
			if (value) {
				this.contactN = value.name,
				this.contactP = value.phone,
				this.contactA = value.ads,
				this.contactAll = value.adsall
			}
		},
		onLoad(){
			try {
				uni.clearStorageSync('Phone');
			}catch (e) {
				// error
			}
		}
	}
</script>

<style>
	.content{
		box-shadow: 0 8px 10px -8px #eee inset;
		border-top: 1px solid #eee;
	}
	
	.release_boxO {
		background: #fff;
		padding: 0 40upx;
		width: 100%;
		box-sizing: border-box;
		border-bottom: 20upx solid #ebedf5;
	}

	.release_boxO_li {
		line-height: 100upx;
		border-bottom: 1upx solid #eeeeee;
		height: 100upx;
	}

	.release_boxO_li::last-child {
		border-bottom: none;
	}

	.release_boxO_li .title {
		display: inline-block;
		float: left;
	}

	.release_boxO_li_R {
		color: #a4a8b4;
		font-size: 24upx;
		display: inline-block;
		float: right;
		width: 390upx;
		text-align: right;
	}

	.release_boxO_li_R picker {
		color: #a4a8b4;
		font-size: 24rpx;
		display: inline-block;
	}

	.release_boxO_li_R picker view {
		color: #a4a8b4;
		font-size: 24rpx;
		display: inline-block;
	}

	.release_boxO_li_R .iconfont {
		font-size: 30upx;
		font-weight: 600;
	}

	.release_boxT_top {
		padding: 0 40upx;
		width: 100%;
		box-sizing: border-box;
		border-bottom: 1upx solid #eee;
	}

	.release_boxT_title {
		border-bottom: 1upx solid #eee;
		line-height: 100upx;
	}

	.release_boxT_keyword {
		padding: 20upx 0;
	}

	.release_boxT_keyword text {
		color: #596ffe;
		border: 1px solid #596ffe;
		line-height: 55upx;
		padding: 0 40upx;
		display: inline-block;
		margin: 20upx;
		font-size: 28upx;
		border-radius: 50upx;
	}

	.release_boxT_bottom {
		padding: 0 40upx;
		width: 100%;
		box-sizing: border-box;
	}

	.release_boxT_contact_li {
		display: flex;
		justify-content: space-between;
		line-height: 75upx;
		align-items: center;
	}
	.release_boxT_contact_li .name{
		width: 130upx;
	}
	.release_boxT_contact {
		padding: 0 40upx;
		width: 100%;
		box-sizing: border-box;
	}

	.release_boxT_contact_li .iconfont {
		color: #596ffe;
		font-size: 36upx;
		font-weight: 600;
	}

	.push {
		background: #ff5d76;
		border: none;
		width: 250upx;
		height: 70upx;
		line-height: 70upx;
		color: #fff;
		border-radius: 50upx;
		font-size: 34upx;
		margin: 70upx auto;
	}
	.contact_zi{
		font-size: 26rpx;
		color: #888888;
		width:390upx;
		text-align:right;
		line-height:40upx;
	}
</style>
